package solutionsdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2024-01-26
 * Time: 1:12
 */

/**
 * 反转二叉树：
 */
public class InvertTree {
    public TreeNode invertTree(TreeNode root) {
        if(root == null) {
            return null;
        }

        //将根节点的左右子树进行交换
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;

        //对左右子树也进行交换操作（左右子树的左右子树进行反转）
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }
}
